//
//  WFFarmListHeaderView.m
//  WisdomFarm
//
//  Created by sky on 2017/10/31.
//  Copyright © 2017年 sky. All rights reserved.
//

#import "WFFarmListHeaderView.h"

@implementation WFFarmListHeaderView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = [UIColor whiteColor];
        
        _iconView = [[UIImageView alloc] init];
        [self addSubview:_iconView];
        [_iconView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(23);
            make.centerY.offset(0);
        }];
        _iconView.image = [UIImage imageNamed:@"home_edit_loction"];
        
        _addressLabel = [[UILabel alloc] init];
        [self addSubview:_addressLabel];
        [_addressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.iconView.mas_right).offset(13);
            make.centerY.offset(0);
        }];
        _addressLabel.font = SCFont(14);
        _addressLabel.textColor = [UIColor textContentColor];
        _addressLabel.hidden = YES;
        
        _indicatorView = [[UIActivityIndicatorView alloc] init];
        [self addSubview:_indicatorView];
        [_indicatorView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.iconView.mas_right).offset(13);
            make.centerY.offset(0);
        }];
        [self.indicatorView startAnimating];
        self.indicatorView.hidesWhenStopped = YES;
        
        _coverButton = [[UIButton alloc] init];
        [self addSubview:_coverButton];
        [_coverButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.insets(UIEdgeInsetsZero);
        }];
    }
    return self;
}

- (void)setIsLocated:(BOOL)isLocated {
    if (isLocated) {
        [self.indicatorView stopAnimating];
        self.addressLabel.text = [WFCacheStore sharedCacheStore].currentAddress;
        self.addressLabel.hidden = NO;
    } else {
        [self.indicatorView startAnimating];
        self.addressLabel.hidden = YES;
    }
}

@end
